// pages/out/out.js
const app = getApp();

var util = require('../../utils/util.js')
var time
var date
Page({

  /**
   * 页面的初始数据
   */
  data: {
    time: '',
    date: '',
    index: 0,
    health:["健康","乏力", "咳嗽", "发烧", "疑似新冠状病毒感染", "确诊新冠状病毒感染"],
    healths:'健康',
    name:'',
    temp: '',
    year:'',
    sex:'',
  //  / destination:'',
    // reason:'',
    // carnumber:'',
    phone: '',
    address:'',
    idcard:'',
    id_number:null,
    sex:"",
    userInfo: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // console.log(options.title)
    //获取当前时间日期，自动填写
    this.setData({
      name:getApp().globalData.name,
      id_number:getApp().globalData.id_number,
      openid:getApp().globalData.Uopenid,
      address:getApp().globalData.room_id,
    })
    let that = this;
    let realtime = util.formatTime(new Date());
    date = realtime.substring(0, 4) + "-" + realtime.substring(5, 7) + "-" + realtime.substring(8, 10)
    time = realtime.substring(11, 16)
    console.log(date)
    console.log(time)
    wx.getStorage({
      key: 'userInfo',
      success: function (res) {
        that.setData({
          userInfo: res.data
        })
      },
    })
    that.setData({
      date: date,
      time: time,
      userInfo: app.globalData.userInfo
    })
  },

  //接收用户体温
  inputTemp: function (e) {
    console.log(e.detail.value)
    this.setData({
      temp: e.detail.value,
    })
  },
  

  //提交按钮，向数据库中存入数据
  tijiao: function () {
    console.log("健康:"+this.data.healths)
    console.log("提交数据")
    let that = this
    //添加必要的输入是否为空判断
    if (that.data.temp == ''){
      wx.showModal({
        title: '提示!',
        content: '请输入体温',
      })
    }
    else if(getApp().globalData.isSetInfo == true&&getApp().globalData.inspector_openid!=null){
      console.log(getApp().globalData.inspector_openid+getApp().globalData.Uopenid+date+that.data.temp)
    wx.request({
     
      url:'http://47.94.215.148:8080/weiChe/addTemp',
      method:'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data:{
        che_open_id:getApp().globalData.inspector_openid,
        res_open_id:getApp().globalData.Uopenid,
        date:date,
        temperature:that.data.temp  
      },
      success:function(res){
        console.log(res)
        if(res.data.status==1){
          wx.showModal({
            title: '提示',
            content: '录入体温信息成功',
          })
          wx.switchTab({
            url: '../../pages/home/home',
          })
        }
        else{
          wx.showModal({
            title: '提示',
            content: '录入体温信息失败',
          })
        }
        
      },
      fail:function(res){
        console.log("失败"+res)
        wx.showModal({
          title: '提示',
          content: '录入体温信息失败',
        })
      }
    })
  }else{
    wx.showModal({
      title: '提示',
      content: '你还不是检查人员',
    })
  }
  }
 

})